package edu.gatech.cc.CFAWaffleFriesWheresMyStuff.common;

import java.util.ArrayList;
import java.util.List;

/**
 ** The User object class. Holds and operates on a User's personal information.
 ** @author Dakota Lindsey
 */
public class User {
	
	protected String _username;
	protected String _password;
	protected String _name;
	protected String _phoneNumber;
	protected String _email;
	protected int _loginAttempts = 0;
	protected boolean _isLocked = false;
	protected List<Item> _userItems;
	
	/**
	 ** Instantiates a new User object.
	 */
    public User() {
    	_username = "";
    	_password = "";
    	_name = "";
    	_phoneNumber = "";
    	_email = "";
    	_loginAttempts = 0;
    	_isLocked = false;
    	_userItems=new ArrayList<Item>();
	}
    
    /**
	 ** Instantiates a new User object with the given information.
	 ** @param username The username of the User to be created
	 ** @param password The password of the User to be created
	 ** @param name The name of the User to be created
	 ** @param phonenumber The phone number of the User to be created
	 ** @param email The email of the User to be created
	 */
    public User(String username, String password, String name, String phonenumber, String email)
    {
    	_username = username;
    	_password = password;
    	_name = name;
    	_phoneNumber = phonenumber;
    	_email = email;
    	_loginAttempts = 0;
    	_isLocked = false;
    	_userItems=new ArrayList<Item>();
    }
    
    /**
	 * Instantiates a new User object with the given information.
	 * @param username The username of the User to be created
	 * @param password The password of the User to be created
	 * @param name The name of the User to be created
	 * @param phonenumber The phone number of the User to be created
	 * @param email The email of the User to be created
	 * @param loginAttempts The number of login attempts by this user
	 * @param isLocked The lock status of this user
	 */
    public User(String username, String password, String name, String phonenumber, String email, int loginAttempts, boolean isLocked)
    {
    	_username = username;
    	_password = password;
    	_name = name;
    	_phoneNumber = phonenumber;
    	_email = email;
    	_loginAttempts = loginAttempts;
    	_isLocked = isLocked;
    	_userItems=new ArrayList<Item>();
    }
    
    /**
	 ** Grabs a User's username attribute.
	 ** @return _username The username of the User
	 */
    public String getUsername()
    {
    	return _username;
    }
    
    /**
	 ** Sets a User's username attribute to the indicated string.
	 ** @param username The username entered by the User.
	 */
    public void setUsername(String username)
    {
    	_username = username;
    }
    
    /**
	 ** Grabs a User's password attribute.
	 ** @return _password The password of the User
	 */
    public String getPassword()
    {
    	return _password;
    }
    
    /**
	 ** Sets a User's password attribute to the indicated string.
	 ** @param password The password entered by the User.
	 */
    public void setPassword(String password)
    {
    	_password = password;
    }
    
    /**
	 ** Grabs a User's name attribute.
	 ** @return _name The name of the User
	 */
    public String getName()
    {
    	return _name;
    }
    
    /**
	 ** Sets a User's name attribute to the indicated string.
	 ** @param name The name entered by the User.
	 */
    public void setName(String name)
    {
    	_name = name;
    }
    
    /**
	 ** Grabs a User's phone number attribute.
	 ** @return _phoneNumber The phone number of the User
	 */
    public String getPhone()
    {
    	return _phoneNumber;
    }
    
    /**
	 ** Sets a User's phone number attribute to the indicated string.
	 ** @param phonenumber The phone number entered by the User.
	 */
    public void setPhone(String phonenumber)
    {
    	_phoneNumber = phonenumber;
    }
    
    /**
	 ** Grabs a User's email address attribute.
	 ** @return _email The email address of the User
	 */
    public String getEmail()
    {
    	return _email;
    }
    
    /**
	 ** Sets a User's email address attribute to the indicated string.
	 ** @param email The email address entered by the User.
	 */
    public void setEmail(String email)
    {
    	_email = email;
    }
    
    /**
	 ** Grabs a User's login attempts attribute.
	 ** @return _loginAttempts The login attempts of the User
	 */
    public int getAttempts()
    {
    	return _loginAttempts;
    }
    
    /**
	 ** Sets a User's login attempts to the indicated integer.
	 ** @param attempts The number of login attempts entered.
	 */
    public void setLoginAttempts(int attempts)
    {
    	_loginAttempts = attempts;
    }
    
    /**
	 ** Grabs a User's lock status attribute.
	 ** @return _isLocked A boolean corresponding to the current lock status of the User
	 */
    public boolean getLockStatus()
    {
    	return _isLocked;
    }
    
    /**
	 ** Locks a User out of the system.
	 */
    public void lockUser()
    {
    	_isLocked = true;
    }
    
    /**
	 ** Allows a User into the system.
	 */
    public void unlockUser()
    {
    	_isLocked = false;
    }
    
    /**
	 ** Increments a User's login attempts by one.
	 ** If login fails three times, the User is locked out of the system.
	 ** Called by the Login class.
	 */
    public void loginFailed()
    {
    	if(_loginAttempts < 3)
    		_loginAttempts++;
    	if(_loginAttempts == 3)
    		lockUser();
    }
    
    /**
	 ** Checks to see if the User's password matches the one entered at login.
	 ** @param password The password entered by the User
	 ** @return boolean True if passwords match, false if passwords do not match.
	 */
    public boolean checkPassword(String password)
    {
    	return (getPassword().equals(password));
    }
    /**
     * Setter for _userItems, the user's internal item list. Used in item creation.
     * @param newUserItems the new user item list 
     * @author Michael Luke Hawkins
     */
    public void setUserItems(List<Item> newUserItems)
    {
    	_userItems = newUserItems;
    }
    /**
     * Getter for _userItems, the user's internal item list.
     * @return _userItems the user's internal item list. 
     * @author Michael Luke Hawkins
     */
    public List<Item> getUserItems()
    {
    	return _userItems;
    }
    
    /**
     * Used to determine admin access.
     * @return false
     */
    public boolean isAdmin(){
    	return false;
    }
    
    @Override
    public boolean equals(Object o) {
    	User otherUser = (User)o;
    	if(otherUser == null)
    		return false;
    	if(!_username.equals(otherUser.getUsername()) || !_password.equals(otherUser.getPassword()) || !_name.equals(otherUser.getName()) || !_phoneNumber.equals(otherUser.getPhone()) || !_email.equals(otherUser.getEmail()))
    		return false;
    	return true;
    }

}
